package com.training1.core.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.training1.core.common.controller.BaseController;
import com.training1.core.common.entity.RespJson;
import com.training1.core.common.utils.framework.RespJsonFactory;
import com.training1.core.entity.SystemUserEntity;
import com.training1.core.modules.service.SystemUserService;

@Controller
@RequestMapping("huangyan")
public class HuangYanController extends BaseController{
	
	/**
	 * 首页面
	 * @return
	 */
	@RequestMapping("huangyansetting")
	public String managersetting(){
		return "huangyan/huangyanSetting";
	}
	/**
	 * JS的简单运算：加减乘除
	 * @return
	 */
	@RequestMapping("arithmeticsetting")
	public String arithmeticsetting(){
		return "huangyan/arithmeticSetting";
	}
	/**
	 * JS：取值赋值
	 * @return
	 */
	@RequestMapping("valuesetting")
	public String valuesetting(){
		return "huangyan/valueSetting";
	}
	/**
	 * JS：AJAX
	 * @return
	 */
	@RequestMapping("ajaxsetting")
	public String ajaxsetting(){
		return "huangyan/ajaxSetting";
	}
	
	@Resource
	private SystemUserService systemUserService;
	
	
	/**
	 * Java：switch函数
	 * @return
	 */
	@RequestMapping("switchsetting")
	public String switchsetting(){
		return "huangyan/switchSetting";
	}
	/**
	 * Java：substring函数
	 * @return
	 */
	@RequestMapping("substringsetting")
	public String substringsetting(){
		return "huangyan/substringSetting";
	}
	/**
	 * SQL：增删改查
	 * @return
	 */
	@RequestMapping("selectsetting")
	public String selectsetting(){
		return "huangyan/selectSetting";
	}
	/**
	 * SQL：多表查询
	 * @return
	 */
	@RequestMapping("unionsetting")
	public String unionsetting(){
		return "huangyan/unionSetting";
	}
	/**
	 *switch测试
	 * @return
	 */
	@RequestMapping("switchtest")
	@ResponseBody
	public Object test1(String month){
		int m = Integer.parseInt(month);
		String jijie = "";
		switch (m) {
		case 1:
		case 2://输出结果相同可这样写
		case 3:
			jijie= "spring";
			break;//退出switch语句
			//System.exit(0);//系统退出
		case 4:
		case 5:
		case 6:
			jijie= "summer";
			break;
		case 7:
		case 8:
		case 9:
			jijie= "autumn";
			break;
		case 10:
			jijie= "winter";
			break;
			//当所有的case不匹配，有default，执行此语句
		default://可以在任意的case语句之间，如果没有break，继续执行下面的语句
			jijie= "没有这个月份";
			break;
		case 11:
			jijie= "winter";
			break;
		case 12:
			jijie= "winter";
			break;
		}
		Map<Integer,String> map = new HashMap<>();
		map.put(1,jijie);
		return map;
	}
	
	/**
	 * substrng测试
	 * @return
	 */
	@RequestMapping("substringtest")
	@ResponseBody
	public Object test2(String str){
		Map<Integer,String> map = new HashMap<>();
		String jiequ1 = str.substring(str.length()-1);
		map.put(1,jiequ1);
		if(str.length()>3){
			String jiequ2 = str.substring(0,3);
			map.put(2,jiequ2);
		}else{
			map.put(2,null);
		}
		return map;
	}
	
	/**
	 * 查询
	 */
	@RequestMapping("list")
	@ResponseBody
	public List<SystemUserEntity> list(int isValid,String userName, String userAccount){
		Map<String,Object> map = new HashMap<>();
		map.put("userName", userName);
		map.put("userAccount", userAccount);
		map.put("validFlag", isValid);
		List<SystemUserEntity> list = systemUserService.findList(map);
		return list;
	}
	/**
	 * 插入
	 */
	@RequestMapping("save")
	@ResponseBody
	public RespJson save(String userName,String isValid){
		SystemUserEntity su = new SystemUserEntity();
		su.setuserName(userName);
		su.setValidFlag(Integer.valueOf(isValid));
		systemUserService.save(su);
		return RespJsonFactory.buildSuccess();
	}
	/**
	 *更新
	 */
	@RequestMapping("update")
	@ResponseBody
	public RespJson update(String id,String userName){
		SystemUserEntity su = new SystemUserEntity();
		su.setId(Integer.valueOf(id));
		su.setuserName(userName);
		systemUserService.save(su);
		return RespJsonFactory.buildSuccess();
	}
	/**
	 * 删除
	 */
	@RequestMapping("delete")
	@ResponseBody
	public RespJson delete(String id){
		systemUserService.delete(Integer.valueOf(id));
		return RespJsonFactory.buildSuccess();
	}
	/**
	 * union连接
	 */
	@RequestMapping("union")
	@ResponseBody
	public List<SystemUserEntity> union(){
		List<SystemUserEntity> list = systemUserService.union();
		return list;
	}
	/**
	 * unionAll连接
	 */
	@RequestMapping("unionAll")
	@ResponseBody
	public List<SystemUserEntity> unionAll(){
		List<SystemUserEntity> list = systemUserService.unionAll();
		return list;
	}
	/**
	 * 逗号实现交叉连接
	 */
//	@RequestMapping("crossjoin")
//	@ResponseBody
//	public List<SystemUserEntity> crossjoin(){
//		List<SystemUserEntity> list = systemUserService.crossjoin();
//		return list;
//	}
	/**
	 * 子查询
	 */
	@RequestMapping("ziSearch")
	@ResponseBody
	public List<SystemUserEntity> ziSearch(){
		List<SystemUserEntity> list = systemUserService.ziSearch();
		return list;
	}
}
